package com.bike.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bike.entity.HhFoodMenu;
import com.bike.mapper.HhFoodMenuMapper;
import com.bike.util.PageData;
import com.bike.util.TimeManager;
import com.bike.util.TransFerUtil;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;

@Service
public class HhFoodMenuServiceImpl extends BaseServcieImpl  {

	@Autowired
	HhFoodMenuMapper hhFoodMenuMapper;
	
	/**
	* 保存
	*/
	public int saveOrUpdate(PageData pd, HhFoodMenu record) {
		if(pd.getLong("foodMenuId")>0){
			 //编辑
			return hhFoodMenuMapper.updateByPrimaryKeySelective(record);
		}else{
			record.setAddTime(TimeManager.currentTime());
			return hhFoodMenuMapper.insertSelective(record);
		}
	}
	
	/**
	* 删除
	*/
	public int deleteHhFoodMenuById(long hhFoodMenu) {
		
		HhFoodMenu foodMenu=new HhFoodMenu();
		foodMenu.setFoodMenuId(hhFoodMenu);
		foodMenu.setStatus(1);
		return hhFoodMenuMapper.updateByPrimaryKeySelective(foodMenu) ;
	}
	
	/**
	*列表分页
	*/
	public PageData selectHhFoodMenuList(PageData pd) {
		PageData result=new PageData();
		PageBounds pageBounds=(PageBounds) pd.get("pageB");
		 
		List<HhFoodMenu> records= hhFoodMenuMapper.selectByPage(pd,pageBounds);
		result.put("rows",records );
		result.put("total", ((PageList<HhFoodMenu>) records).getPaginator().getTotalCount());
		return result;
	}
	 
	
	/**
	*列表(全部)
	*/
	public List<HhFoodMenu> listAll(PageData pd) {
		return  hhFoodMenuMapper.selectAll(pd);
	}
	
	/**
	* 通过id获取数据
	*/
	public HhFoodMenu selectByHhFoodMenuId(Long hhFoodMenu) {
		return hhFoodMenuMapper.selectByPrimaryKey(hhFoodMenu);
	}

	public int insertBatch(PageData pd) {
		return hhFoodMenuMapper.insertBatch(pd);
	}
}

